import { defineConfig } from "vite";
import path from "path";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import Components from "unplugin-vue-components/vite";
import uni from "@dcloudio/vite-plugin-uni";
import AutoImport from "unplugin-auto-import/vite";
const pathSrc = path.resolve(__dirname, "src");
import VueSetupExtend from "vite-plugin-vue-setup-extend";
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    uni(),
    VueSetupExtend(),
    AutoImport({
      // Auto import functions from Vue, e.g. ref, reactive, toRef...
      // 自动导入 Vue 相关函数，如：ref, reactive, toRef 等
      imports: ["vue"],
      resolvers: [ElementPlusResolver()],

      dts: path.resolve(pathSrc, "auto-imports.d.ts"),
    }),
    Components({
      dirs: [], // , 'src/views/...'
      //   // 按需引入组件，不需要在import 了！
      //  // extensions: ["vue", "md"],
      //   // 允许自动引入的组件尾缀！
      //  // include: [/\.vue$/, /\.vue\?vue/, /\.md$/, /\.ts$/],
      //   resolvers: [
      //     // ElementPlusResolver({
      //     //   importStyle: "sass",
      //     // }),
      //   ],
      // dts: "src/components.d.ts", // 自动引入文件后，生成的文件列表，js版注释掉
    }),
  ],
  resolve: {},
  build: {
    // minify: "terser",
    // terserOptions: {
    //   compress: {
    //     drop_console: true,
    //   },
    // },
  },
  server: {
    open: true,
    host: "0.0.0.0",
    port: 9999, //更改启动端口
    //hmr: false,
    // 代理
    proxy: {
      "/api": {
       //  target: "https://websocket.xhcss.com/api",
        target: "http://127.0.0.1:3680",
        changeOrigin: true,
        secure: false,
       // rewrite: (path) => path.replace(/^\/api/, "/"),
      },
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/style/mixin.module.scss" as *;`,
      },
    },
  },
});
